package com.unknowpupil.design.strategy.demo;


import java.util.Arrays;

/**
 * Created at 2020/12/10 by w10g <br>
 * Initialize 策略模式 ... <br>
 *
 * @author unknowpupil
 * @since 0.0.1
 */
public class 策略模式 {

}
class Main{
    public static void main(String[] args) {
        int [] a = {9,2,3,5,7,1,4};
        Sorter sorter = new Sorter();

        sorter.sort(a);
        System.out.println(Arrays.toString(a));

        Cat[] cats = {new Cat(5,5),new Cat(3,3),new Cat(2,2),};
        Dog[] dogs = {new Dog(5,5),new Dog(3,3),new Dog(2,2),};


        Sorter<Dog> sorter1 = new Sorter();
        // 当方法中只有一个接口的时候就可以用lambda方式写。这种被春伟函数式编程
        sorter1.sort(dogs,(o1, o2) -> {
                if (o1.weight > o2.weight) return 1;
                else if (o1.weight < o2.weight) return -1;
                else return 0;
        });
        System.out.println(Arrays.toString(dogs));
    }
}


